package petstore.web.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class WelcomePageForm extends HttpServlet {
    private String WELCOME_PAGE = "/WEB-INF/jsp/storePage/storePageMain.jsp";

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //新建session记录是否登录，判断是否登录
        HttpSession session = req.getSession(true);
        Object obj = session.getAttribute("username");
        if(obj ==  null)//未登录
        {
            System.out.println("用户未登录");
            session = req.getSession(true);
            session.setAttribute("isLogged", false);
        }
        else
            System.out.println("登录用户：" + session.getAttribute("username"));
        req.getRequestDispatcher(WELCOME_PAGE).forward(req,resp);
    }
}
